package com.xiexuan.asus1.servicedemo;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.widget.Toast;

import static java.lang.Thread.sleep;


public class MyService extends Service {


    public MyService() {
    }

    private Handler handler;

    @Override
    public void onCreate() {
        super.onCreate();
        handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            int i = 0;

            @Override
            public void run() {
                for (; i < 5; i++) {
                    Toast.makeText(getApplicationContext(), i + "", Toast.LENGTH_SHORT).show();
                    try {
                        sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }

   /* @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        new Thread() {
            @Override
            public void run() {
                super.run();
                while (true) {

                    Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
                    try {
                        sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };

        return super.onStartCommand(intent, flags, startId);
    }*/

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
